package cz.tomasdvorak.cars.wicket.components.table;

import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.navigation.paging.IPageable;
import org.apache.wicket.markup.html.navigation.paging.IPagingLabelProvider;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigation;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;

public class StyledPagingNavigator extends PagingNavigator {
    public StyledPagingNavigator(String id, IPageable pageable) {
        super(id, pageable);
    }

    public StyledPagingNavigator(String id, IPageable pageable,
                                 IPagingLabelProvider labelProvider) {
        super(id, pageable, labelProvider);
    }

    @Override
    protected PagingNavigation newNavigation(IPageable pageable,
                                             IPagingLabelProvider labelProvider) {
        return new PagingNavigation("navigation", pageable, labelProvider) {
            @Override
            protected void populateItem(LoopItem loopItem) {
                super.populateItem(loopItem);
                loopItem.visitChildren(Link.class, new IVisitor<Link>() {
                    public Object component(Link link) {
                        link.setBeforeDisabledLink("<span class=\"current\">");
                        link.setAfterDisabledLink("</span>");
                        return CONTINUE_TRAVERSAL;
                    }
                });
            }
        };
    }
}
